package com.ea.eadp.nexus.test.pageDefinition.mobile;

import com.ea.eadp.nexus.test.common.TestUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;


public class ResetPage extends MobileBasePage {
    public final static String resetPage = "resetPasswordPage";
    public static final String emailInputBox = "reset-email";

    public ResetPage(WebDriver driver) {
        super(driver, ResetPage.class, resetPage);
    }

    public void enterResetEmail(String email) {
        log.info("Enter Reset Password Email:" + email);
        sendInput(emailInputBox, email);
        driver.findElement(By.xpath("//form[@id='resetPasswordForm']/div[2]/div[1]/input")).click();
        Assert.assertFalse(getResetResponse().isEmpty());
    }

    public void validateResetEmail(String email, String errorMessage) {
        log.info("Validate Reset Password Email:" + email);
        sendInput(emailInputBox, email);
        driver.findElement(By.xpath("//form[@id='resetPasswordForm']/div[2]/div[1]/input")).click();
        TestUtil.sleep(1);
        Assert.assertEquals(getResetEmailInvalidError(), errorMessage, "Input not trigger the correct error message");
    }

    public String getResetEmailInvalidError() {
        return getElementStringByXPath("//form[@id='resetPasswordForm']/div[1]/div/span[2]");
    }

    public String getResetResponse() {
        TestUtil.sleep(1);
        return getElementStringByXPath("//div[@id='reset-popup']/div[2]/div[1]");
    }
}
